import { FC, useEffect, useState } from 'react';
import { UploadOutlined } from '@ant-design/icons';
import { Button, Upload } from 'antd';
import type { UploadFile, UploadProps } from 'antd';

const Index: FC<any> = (props: any): JSX.Element => {
  const headers = { Authorization: sessionStorage.getItem("token")! }


  const [fileList, setFileList] = useState<any[]>([]);


  useEffect(() => {

    setFileList([{
      uid: '-1',
      name: 'yyy.png',
      status: 'done',
      oldUrl: "2024/01/26/202401261505142194962.jpg",
      url: 'http://apis.90000p.com/estate/upload/2024/01/26/202401261505142194962.jpg',
    }])


  }, [])

  const onChange: UploadProps['onChange'] = ({ fileList: newFileList }) => {
    setFileList(newFileList);
  };


  const submit = () => {

    let files = fileList.map((item: any) => ({ url: item.response ? item.response.data : item.oldUrl }))

    console.log(11111111111, files);


  }
  return (
    <div>
      <Upload
        action={import.meta.env.VITE_BASE_URL + 'api/upload/add'}
        headers={headers}
        listType="picture"
        onChange={onChange}
        fileList={[...fileList]}
      >
        <Button icon={<UploadOutlined />}>Upload</Button>
      </Upload>

      <button onClick={submit}>提交</button>
    </div>
  )
}
export default Index;